<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="../js/jquery-1.10.0.js"></script>
<style>
#index a
{
	background:#06F;
	color:#FFF;
	width:100px;
	height:40px;
	text-align:center;
	font-size:20px;
	text-decoration:none;
}
<
</style>
</head>
<body>
<?php
	if(isset($_SESSION["s_user"]))
	{
		include "../app_sv/check_user.php";
		if(!$is_sv)
		{
?>
<div id="index"><a href="../index.php">Trang Chủ</a></div>
<center>
<label for='subjectID'>Mã Môn Học</label>
<select name='subjectID' id='subjectID'>
<?php
include("../app/connection.php");
session_start();
//$user="GV007";
$user = $_SESSION["s_user"];
$result = mysql_query("select distinct MAMONHOC from LOP where MAGIAOVIEN = '$user'");
while($row = mysql_fetch_array($result))
{
	echo "<option value='$row[0]'>$row[0]</option>";
}
?>
</select>
<img src='' id='subjectIDimg'/>
<br>
<br />
<div id="semeterIDdiv">
</div>
<br>
<br />
<div id="YearIDdiv">
</div>
<br />
<br />
<label for="filetype">Loại File</label>
<select name="filetype" id="filetype">
<option value="excel">Excel</option>
<option value="PDF">PDF</option>
</select>
<input type="button" value="Export" id="export"/>
<img src="" id='123abc' />
<br />
<br />
<div id="result">
</div>
</center>
<?php
		}//end check giaovien
		else
		{
			echo "<script>alert('Quyen thuc thi cua giang vien')</script>";
			echo "<meta http-equiv=\"refresh\" content=\"0; URL=../index.php\">";
		}
	}
	else
	{
		echo "<script>alert('Ban chua dang nhap')</script>";
		echo "<meta http-equiv=\"refresh\" content=\"0; URL=../index.php\">";
	}
?>
<script>
$(document).ready(function(e) {
	$("input[type=button]").click(function(){
		$("#123abc").attr("src","../image/source/loader.gif");
		$.ajax({
			url:"ajax_teacherExport.php",
			data:{filetype:$("#filetype").val(),subjectID: $("#subjectID").val(),semeterID: $("#semeterID").val(),yearID: $("#YearID").val()}
		}).done(function(msg){
			pos = msg.indexOf("exported");
			pos1=msg.indexOf(".php");
			var temp =msg.substring(pos,pos1);
			$("#123abc").attr("src","");
			window.location=temp;
			
		});
	});
	////////////////////////////////////////////
	$("#subjectIDimg").attr("src","../image/source/loader.gif");
		$.ajax({
			url:"ajax_getSemeterID.php",
			data:{subjectID:$("#subjectID").val()}
		}).done(function(msg){
			$("#semeterIDdiv").html(msg);
			$("#subjectIDimg").attr("src","");
			///////////////////////////////
			$("#semeterIDimg").attr("src","../image/source/loader.gif");
			$.ajax({
				url:"ajax_getYearID.php",
				data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val()}
				}).done(function(msg){
					$("#YearIDdiv").html(msg);
					$("#semeterIDimg").attr("src","");
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					$("#YearID").change(function(){
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					});
				});
			$("#semeterID").change(function(){
			$("#semeterIDimg").attr("src","../image/source/loader.gif");
			$.ajax({
				url:"ajax_getYearID.php",
				data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val()}
				}).done(function(msg){
					$("#YearIDdiv").html(msg);
					$("#semeterIDimg").attr("src","");
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					$("#YearID").change(function(){
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					});
				});
		  	});
		});
	$("#subjectID").change(function(){
		$("#subjectIDimg").attr("src","../image/source/loader.gif");
		$.ajax({
			url:"ajax_getSemeterID.php",
			data:{subjectID:$("#subjectID").val()}
		}).done(function(msg){
			$("#semeterIDdiv").html(msg);
			$("#subjectIDimg").attr("src","");
			///////////////////////////////
			$("#semeterIDimg").attr("src","../image/source/loader.gif");
			$.ajax({
				url:"ajax_getYearID.php",
				data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val()}
				}).done(function(msg){
					$("#YearIDdiv").html(msg);
					$("#semeterIDimg").attr("src","");
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					$("#YearID").change(function(){
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					});
				});
			$("#semeterID").change(function(){
			$("#semeterIDimg").attr("src","../image/source/loader.gif");
			$.ajax({
				url:"ajax_getYearID.php",
				data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val()}
				}).done(function(msg){
					$("#YearIDdiv").html(msg);
					$("#semeterIDimg").attr("src","");
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					$("#YearID").change(function(){
					$("#123abc").attr("src","../image/source/loader.gif");
					$.ajax({
							url:"teacherExportFilter.php",
							data:{subjectID:$("#subjectID").val(),semeterID:$("#semeterID").val(),yearID:$("#YearID").val()}
							}).done(function(msg){
								$("#result").html(msg);
								$("#123abc").attr("src","");
							});
					});
				});
		  	});
		});
	});
	
});
</script>
</body>
</html>